package cn.itcalvin.sncoal.cth.controller;

import cn.itcalvin.sncoal.cth.aspect.LogAnnotation;
import cn.itcalvin.sncoal.cth.aspect.RoleAnnotation;
import cn.itcalvin.sncoal.cth.pojo.common.ReqLong;
import cn.itcalvin.sncoal.cth.pojo.common.RespCommon;
import cn.itcalvin.sncoal.cth.pojo.common.RespUserInfo;
import cn.itcalvin.sncoal.cth.pojo.req.mine.ReqMineModify;
import cn.itcalvin.sncoal.cth.pojo.response.mine.RespMine;
import cn.itcalvin.sncoal.cth.service.InfoMineService;
import cn.itcalvin.sncoal.cth.utils.JwtUtil;
import cn.itcalvin.vo.Message;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "矿井")
@RestController
@RequestMapping("/api/mine")
public class MineController {
    @Resource
    InfoMineService infoMineService;

    @ApiOperation(value = "获取矿区矿井列表-下拉选择使用")
    @LogAnnotation(value = "获取矿区矿井列表-下拉选择使用")
    @RoleAnnotation(value = "1,2,3")
    @PostMapping("/getAllMineListBySelect")
    public Message<List<RespCommon>> getAllMineListBySelect(){
        final RespUserInfo userInfo = JwtUtil.getUserInfo();
        Long mineAreaId=null;
        if(userInfo.getRoleType()==3){
            mineAreaId=userInfo.getBelongId();
        }
        return infoMineService.getAllMineListBySelect(mineAreaId);
    }

    @ApiOperation(value = "获取矿井列表(评分入口)")
    @PostMapping("/getAllMineListByPf")
    @LogAnnotation(value = "获取矿井列表(评分入口)")
    @RoleAnnotation(value = "1,2,3")
    public Message<List<RespMine>> getAllMineListByPf(){
        final RespUserInfo userInfo = JwtUtil.getUserInfo();
        Long mineId=null;
        if(userInfo.getRoleType()==3){
            mineId=userInfo.getBelongId();
        }
        return infoMineService.getAllMineListByPf(mineId);
    }

    @ApiOperation(value = "获取矿井列表-股份和矿业公司使用")
    @PostMapping("/getAllMineList")
    @LogAnnotation(value = "获取矿井列表-股份和矿业公司使用")
    @RoleAnnotation(value = "1,3")
    public Message<List<RespMine>> getAllMineList(){
        Long belongId=null;
        if(JwtUtil.getUserInfo().getRoleType()==3){
            belongId=JwtUtil.getUserInfo().getBelongId();
        }
        return infoMineService.getAllMineList(belongId);
    }


    @ApiOperation(value = "编辑矿井信息")
    @PostMapping("/modify")
    @LogAnnotation(value = "编辑矿井信息")
    @RoleAnnotation(value = "4")
    public Message modify(@RequestBody @Valid ReqMineModify reqMineModify){
        return infoMineService.modify(reqMineModify);
    }

    @PostMapping("/getMineById")
    @LogAnnotation(value = "获取矿井详情")
    public Message<ReqMineModify> getMineById(@RequestBody @Valid ReqLong reqLong){
        return infoMineService.getMineById(reqLong.getId());
    }

    @PostMapping("/getMineInfo")
    @LogAnnotation(value = "获取矿井详情")
    @RoleAnnotation(value = "3,4")
    public Message<ReqMineModify> getMineInfo(){
        return infoMineService.getMineById(JwtUtil.getUserInfo().getBelongId());
    }


}
